]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[StThemeNode] Add basic background-position support
authorAdel Gadllah <adel.gadllah@gmail.com>
Wed, 1 Sep 2010 16:13:43 +0000 (18:13 +0200)
committerAdel Gadllah <adel.gadllah@gmail.com>
Wed, 1 Sep 2010 16:13:43 +0000 (18:13 +0200)
Add basic support for background-position, which only supports absolute
values.

Also don't require an unit to be specified for 0 (because the unit does not
really matter here 0 is 0 regardless of the unit).

https://bugzilla.gnome.org/show_bug.cgi?id=624375

src/st/st-theme-node-drawing.c
src/st/st-theme-node-private.h
src/st/st-theme-node.c

index 0e23caaf6863d834e3d4275b1e5e191367f222e8..ff7ea0cd32acc330ffc4cb42f35434b49934cfba 100644 (file)
@@ -466,8 +466,8 @@ get_background_position (StThemeNode             *self,
   w = cogl_texture_get_width (self->background_texture);
   h = cogl_texture_get_height (self->background_texture);
 
-  /* scale the background into the allocated bounds */
-  if (w > result->x2 || h > result->y2)
+  /* scale the background into the allocated bounds, when not being absolutely positioned */
+  if ((w > result->x2 || h > result->y2) && !self->background_position_set)
     {
       gint new_h, new_w, offset;
       gint box_w, box_h;
@@ -500,9 +500,18 @@ get_background_position (StThemeNode             *self,
     }
   else
     {
-      /* center the background on the widget */
-      result->x1 = (int)(((allocation->x2 - allocation->x1) / 2) - (w / 2));
-      result->y1 = (int)(((allocation->y2 - allocation->y1) / 2) - (h / 2));
+      /* honor the specified position if any */
+      if (self->background_position_set)
+        {
+          result->x1 = self->background_position_x;
+          result->y1 = self->background_position_y;
+        }
+      else
+        {
+          /* center the background on the widget */
+          result->x1 = (int)(((allocation->x2 - allocation->x1) / 2) - (w / 2));
+          result->y1 = (int)(((allocation->y2 - allocation->y1) / 2) - (h / 2));
+        }
       result->x2 = result->x1 + w;
       result->y2 = result->y1 + h;
     }
index 4641df32eee09572ce10394e3492cead737c487b..92d68be74a48d64a143ff952f03831b60c725d7d 100644 (file)
@@ -22,6 +22,10 @@ struct _StThemeNode {
   StGradientType background_gradient_type;
   ClutterColor background_gradient_end;
 
+  int background_position_x;
+  int background_position_y;
+  gboolean background_position_set : 1;
+
   ClutterColor foreground_color;
   ClutterColor border_color[4];
   ClutterColor outline_color;
index 90b156a857accfee65b5ec1ea4078e29da03a3ea..b6000ea371c51f518feaa8870b76eacdbe409e55 100644 (file)
@@ -679,8 +679,19 @@ get_length_from_term (StThemeNode *node,
       return VALUE_NOT_FOUND;
 
     case NUM_GENERIC:
-      g_warning ("length values must specify a unit");
-      return VALUE_NOT_FOUND;
+      {
+        if (num->val != 0)
+          {
+            g_warning ("length values must specify a unit");
+            return VALUE_NOT_FOUND;
+          }
+        else
+          {
+            type = ABSOLUTE;
+            multiplier = 0;
+          }
+        break;
+      }
 
     case NUM_PERCENTAGE:
       g_warning ("percentage lengths not currently supported");
@@ -1424,6 +1435,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
   node->background_computed = TRUE;
   node->background_color = TRANSPARENT_COLOR;
   node->background_gradient_type = ST_GRADIENT_NONE;
+  node->background_position_set = FALSE;
 
   ensure_properties (node);
 
@@ -1450,6 +1462,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
           node->background_color = TRANSPARENT_COLOR;
           g_free (node->background_image);
           node->background_image = NULL;
+          node->background_position_set = FALSE;
 
           for (term = decl->value; term; term = term->next)
             {
@@ -1478,6 +1491,27 @@ _st_theme_node_ensure_background (StThemeNode *node)
                 }
             }
         }
+      else if (strcmp (property_name, "-position") == 0)
+        {
+          GetFromTermResult result = get_length_from_term_int (node, decl->value, FALSE, &node->background_position_x);
+          if (result == VALUE_NOT_FOUND)
+            {
+              node->background_position_set = FALSE;
+              continue;
+            }
+          else
+            node->background_position_set = TRUE;
+            
+           result = get_length_from_term_int (node, decl->value->next, FALSE, &node->background_position_y);
+
+          if (result == VALUE_NOT_FOUND)
+            {
+              node->background_position_set = FALSE;
+              continue;
+            }
+          else
+            node->background_position_set = TRUE;
+        }
       else if (strcmp (property_name, "-color") == 0)
         {
           GetFromTermResult result;